package org.shopen.puremvc.model.domain.testing
{
	import mx.collections.ArrayCollection;
	
	import org.shopen.puremvc.model.domain.ISerializable;

	public class OptionsCollection implements ISerializable
	{
		[Bindable]
		private var _optionsArray : ArrayCollection = new ArrayCollection();
		[Bindable]
		public function get optionsArray() : ArrayCollection
		{
			return _optionsArray;
		}
		public function set optionsArray(value : ArrayCollection) : void
		{
			_optionsArray = value;
		}
		
		public function OptionsCollection(node : XML = null)
		{
			if (node != null)
			{
				deserialize(node);
			}
		}

		public function deserialize(node:XML):void
		{
			optionsArray = new ArrayCollection();
			if ("options" in node)
			{
				for each(var optionNode : XML in node.options..option)
				{
					var option : Option = new Option(optionNode);
					optionsArray.addItem(option); 
				}
			}
		}
		
		public function serialize():XML
		{
			// TODO: consider implement if needed.
			return null;
		}
		
		public function clone() : OptionsCollection
		{
			var result : OptionsCollection = new OptionsCollection();
			result.optionsArray = new ArrayCollection();
			for each(var option : Option in this.optionsArray)
			{
				result.optionsArray.addItem(option.clone());
			}
			return result;
		}
		
	}
}